using System;
using System.Collections.Generic;
using System.Text;
using FlatRedBall;
using FlatRedBall.Input;
using FlatRedBall.AI.Pathfinding;
using FlatRedBall.Graphics.Animation;
using FlatRedBall.Graphics.Particle;

using FlatRedBall.Math.Geometry;
using FlatRedBall.Math.Splines;
using BitmapFont = FlatRedBall.Graphics.BitmapFont;
using Cursor = FlatRedBall.Gui.Cursor;
using GuiManager = FlatRedBall.Gui.GuiManager;

#if FRB_XNA || SILVERLIGHT
using Keys = Microsoft.Xna.Framework.Input.Keys;
using Vector3 = Microsoft.Xna.Framework.Vector3;
using Texture2D = Microsoft.Xna.Framework.Graphics.Texture2D;


#endif

namespace NereusGame.Entities.Projectiles
{
	public partial class Missile
	{
        private const float BODY_WIDTH = 2f;
        private const float BODY_HEIGHT = BODY_WIDTH;
        private Emitter thruster;

        private void CustomInitialize()
        {
            InitializeMissile();
            InitializeEmitter();
        }

		private void CustomActivity()
		{
            if (state == ProjectileState.Alive)
            {
                Acceleration.Y = (float)Math.Sin(RotationZ + 1.5707f) * 20;
                Acceleration.X = (float)Math.Cos(RotationZ + 1.5707f) * 20;
                //thruster.Emit();
            }
		}

		private void CustomDestroy()
		{

            base.Destroy();
		}

        private static void CustomLoadStaticContent(string contentManagerName)
        {


        }

        private void InitializeMissile()
        {
            DeadState();
            Tex.Texture = Missiles;
            Body.ScaleY = Tex.ScaleY = BODY_HEIGHT;
            Body.ScaleX = Tex.ScaleX = BODY_WIDTH;
            lifeCycle = initialLifeCycle = 250;
            DefaultVelocity = 5;
        }

        private void InitializeEmitter()
        {
            thruster = new Emitter();
            thruster.Texture = OrangeThrust;
            thruster.NumberPerEmission = 2;
            thruster.RemovalEvent = Emitter.RemovalEventType.Alpha0;

            thruster.RelativePosition.Y = -1;
            thruster.EmissionSettings.RadialVelocityRange = 5f;
            thruster.EmissionSettings.RadialVelocity = 10f;
            thruster.EmissionSettings.Drag = .9f;
            thruster.EmissionSettings.AlphaRate = -1.5f;
            thruster.EmissionSettings.VelocityRangeType = RangeType.Wedge;
            thruster.EmissionSettings.BlendOperation = FlatRedBall.Graphics.BlendOperation.Add;
            thruster.EmissionSettings.ScaleX = .2f;
            thruster.EmissionSettings.ScaleY = .2f;
            thruster.EmissionSettings.ScaleXVelocity = .5f;
            thruster.EmissionSettings.ScaleYVelocity = .5f;
            thruster.EmissionSettings.WedgeAngle = (float)-Math.PI / 2f;
            thruster.EmissionSettings.WedgeSpread = (float)Math.PI / 16f;
            thruster.AttachTo(Body, false);
        }
	}
}
